/*
 * Servo position control for Flying Fox
 *
 * by Zik Saleeba 2008-02-22
 */

#ifndef SERVO_H
#define SERVO_H

/* local defines */
#define SERVO_HZ 50
#define SERVO_MIN_US 0
#define SERVO_MAX_US (SERVO_MIN_US+SERVO_POSITION_MAX)
#define SERVO_MID_US ((SERVO_SENSIBLE_POSITION_MIN+SERVO_SENSIBLE_POSITION_MAX)/2)
#define SERVO_TIMESLOT_US 2500
#define SERVO_LOAD_US (SERVO_TIMESLOT_US-200)
#define SERVO_NUM_TIMESLOTS 8
#define TIMER2_HZ (SERVO_HZ*SERVO_NUM_TIMESLOTS)
#define TIMER2_TIMESLOT_TICKS (MCK/2 / TIMER2_HZ)
#define SERVO_POSITION_MIN 500
#define SERVO_POSITION_MID 1500
#define SERVO_POSITION_MAX 2500
#define SERVO_SENSIBLE_POSITION_MIN 600
#define SERVO_SENSIBLE_POSITION_MAX 2400


/* functions */

/*
 * NAME:        Servo_Init
 * ACTION:      Initialise the servo subsystem. This sets up timer 2
 *              to do the timing.
 */
void Servo_Init(void);

/*
 * NAME:        Servo_Set
 * ACTION:      Set the position of a servo
 * PARAMETERS:  int Port - which servo to move (0-7)
 *              int Position - what position to move to (in ms)
 */
void Servo_Set(int Port, int Position);

/*
 * NAME:        Servo_Get
 * ACTION:      Get the current position of a servo
 * PARAMETERS:  int Port - which servo to get (0-7)
 * RETURNS:     int - the current servo position (in ms)
 */
int Servo_Get(int Port);

#endif /* SERVO_H */
